package win.demonlegion.service;

import win.demonlegion.mapper.UserMapper;
import win.demonlegion.module.UserBean;
import win.demonlegion.service.inte.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import win.demonlegion.util.MD5Util;

import java.util.List;

/**
 * @Author:Samson
 * @Description:
 * @Date:Created in 2017/5/17.
 */
@Repository
@Service("userService")
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;

    public UserBean login(String uName, String uPwd) {
        return userMapper.login(uName,uPwd);
    }

    @Override
    public UserBean findById(String id) {
        return userMapper.findById(id);
    }


    @Override
    public UserBean selectById(String id) {
        return null;
    }

    @Override
    public int deleteById(String id) {
        return 0;
    }

    @Override
    public int update(UserBean userBean) {
        if(userBean.getuPassword() != null && !userBean.getuPassword().equals(""))
            userBean.setuPassword(MD5Util.MD5(userBean.getuPassword()));
        return userMapper.update(userBean);
    }

    @Override
    public int add(UserBean userBean) {
        if(userBean.getuPassword() != null && !userBean.getuPassword().equals(""))
            userBean.setuPassword(MD5Util.MD5(userBean.getuPassword()));
        return userMapper.add(userBean);
    }

    @Override
    public int count() {
        return 0;
    }

    @Override
    public List<UserBean> findAll() {
        return null;
    }

    @Override
    public List<UserBean> selectUserByKeyword(String keyword, int vaCode) { return userMapper.selectUserByKeyword(keyword, vaCode); }

    @Override
    public UserBean selectByPhone(String phone) {
        return userMapper.selectByPhone(phone);
    }

}
